﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using quanlynhasach.Linksql;

namespace quanlynhasach
{
    public partial class frmTimNV : Form
    {
        Nhanviensql nhanviensql = new Nhanviensql();
        Connection db = new Connection();
        public frmTimNV()
        {
            InitializeComponent();
        }

        private void loadData()
        {
            DataTable NV = new DataTable();
            NV = nhanviensql.getNV();
            dataGridView1.DataSource = NV;
            dataGridView1.AllowUserToAddRows = false;
        }

        private void frmTimNV_Load(object sender, EventArgs e)
        {
            this.Dock = DockStyle.Fill;
            dataGridView1.DefaultCellStyle.ForeColor = Color.Blue;
            loadData();
            radioButton5.Checked = true;
        }

        private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            if (dataGridView1.RowCount > 0)
                pictureBox1.ImageLocation = dataGridView1.Rows[e.RowIndex].Cells["Anh"].Value.ToString();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            DataTable NV = new DataTable();
            if (radioButton2.Checked)
                NV = db.getDS("Select MaNV,TenNV,NgaySinh,GioiTinh,DiaChi,SoDienThoai,SoCMND,Email,Loai,Anh from NhanVien Where MaNV LIKE '%" + textBox1.Text + "%'");
            if (radioButton3.Checked)
                NV = db.getDS("Select MaNV,TenNV,NgaySinh,GioiTinh,DiaChi,SoDienThoai,SoCMND,Email,Loai,Anh from NhanVien Where Loai LIKE '%" + textBox1.Text + "%'");
            if (radioButton1.Checked)
                NV = db.getDS("Select MaNV,TenNV,NgaySinh,GioiTinh,DiaChi,SoDienThoai,SoCMND,Email,Loai,Anh from NhanVien Where TenNV LIKE '%" + textBox1.Text + "%'");
            if (radioButton4.Checked)
                NV = db.getDS("Select MaNV,TenNV,NgaySinh,GioiTinh,DiaChi,SoDienThoai,SoCMND,Email,Loai,Anh from NhanVien Where DiaChi LIKE '%" + textBox1.Text + "%'");
            if (radioButton5.Checked)
                NV = db.getDS("Select MaNV,TenNV,NgaySinh,GioiTinh,DiaChi,SoDienThoai,SoCMND,Email,Loai,Anh from NhanVien Where TenNV LIKE '%" + textBox1.Text + "%' or MaNV LIKE '%" + textBox1.Text + "%' or Loai LIKE '%" + textBox1.Text + "%' or DiaChi LIKE '%" + textBox1.Text + "%'");
            dataGridView1.DataSource = NV;
            if (dataGridView1.RowCount <= 0)
                pictureBox1.ImageLocation = "";
        }
    } 
}